<template>
  <!-- 业绩看板 -->
  <div class="results_wrap">
    <div class="top_wrap">
      <div class="t_top_wrap">
        <div class="t_left">
          <div class="t_left_titel">本月销售目标</div>
          <div class="t_left_num">0.00</div>
        </div>
        <div class="t_bottom">
          <div class="item_wrap">
            <div
              :class="
                item.type === activeType ? 'active_item' : 't_bottom_item'
              "
              v-for="(item, _index) in monthTypeList"
              :key="_index"
              @click="chooseMonthType(item)"
            >
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
      <div class="t_bottom_wrap">
        <template v-if="activeType === 1">
          <div class="t_tottom_top_wrap">
            <div class="item_wrap">
              <div class="title">件单价</div>
              <div class="number">{{ performance.unitPrice || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">实际销售</div>
              <div class="number">{{ performance.actualSales || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">达成率</div>
              <div class="number">{{ performance.achievementRate || 0 }}%</div>
            </div>
            <div class="item_wrap">
              <div class="title">同比去年</div>
              <div class="number">{{ performance.yearOnYearByUp || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">吊牌金额</div>
              <div class="number">{{ performance.tagAmount || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">销售件数</div>
              <div class="number">{{ performance.numberOfSales || 0 }}</div>
            </div>
          </div>
          <div class="t_tottom_bottom_wrap">
            <div class="item_wrap">
              <div class="title">客单价</div>
              <div class="number">{{ performance.customerPrice || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">款数</div>
              <div class="number">{{ performance.numberOfModels || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">连带率</div>
              <div class="number">{{ performance.associateRate || 0 }}%</div>
            </div>
            <div class="item_wrap">
              <div class="title">新品销售占比</div>
              <div class="number">
                {{ performance.proportionOfNewProductSales || 0 }}%
              </div>
            </div>
            <div class="item_wrap">
              <div class="title">环比昨天</div>
              <div class="number">{{ performance.chainRatio || 0 }}%</div>
            </div>
            <div class="item_wrap">
              <div class="title">总票数</div>
              <div class="number">{{ performance.totalVotes || 0 }}</div>
            </div>
          </div>
        </template>
        <template v-else>
          <div class="t_tottom_top_wrap">
            <div class="item_wrap">
              <div class="title">总票数</div>
              <div class="number">{{ performance.totalVotes || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">客单价</div>
              <div class="number">{{ performance.customerPrice || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">件单价</div>
              <div class="number">{{ performance.unitPrice || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">销售件数</div>
              <div class="number">{{ performance.numberOfSales || 0 }}</div>
            </div>
            <div class="item_wrap">
              <div class="title">连带率</div>
              <div class="number">{{ performance.associateRate || 0 }}%</div>
            </div>
            <div class="item_wrap">
              <div class="title">平均折扣</div>
              <div class="number">{{ performance.averageDiscount || 0 }}%</div>
            </div>
          </div>
        </template>
      </div>
    </div>

    <template v-if="activeType === 2">
      <div class="bottom_wrap">
        <div class="bottom_title">本周</div>
        <div class="bottom_item">
          <div class="item_wrap">
            <div class="title">销售目标</div>
            <div class="number">{{ performance.weekSellTarget || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">实际销售</div>
            <div class="number">{{ performance.actualSales || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">达成率</div>
            <div class="number">{{ performance.achievementRate || 0 }}%</div>
          </div>
          <div class="item_wrap">
            <div class="title">环比上周</div>
            <div class="number">{{ performance.chainRatio || 0 }}%</div>
          </div>
          <div class="item_wrap">
            <div class="title">同比去年</div>
            <div class="number">{{ performance.yearOnYear || 0 }}%</div>
          </div>
        </div>
      </div>
      <div class="bottom_wrap">
        <div class="bottom_title">本月</div>
        <div class="bottom_item">
          <div class="item_wrap">
            <div class="title">销售目标</div>
            <div class="number">{{ performance.monthSellTarget || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">实际销售</div>
            <div class="number">{{ performance.actualSalesByUp || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">达成率</div>
            <div class="number">
              {{ performance.achievementRateByUp || 0 }}%
            </div>
          </div>
          <div class="item_wrap">
            <div class="title">环比上月</div>
            <div class="number">{{ performance.chainRatioByUp || 0 }}%</div>
          </div>
          <div class="item_wrap">
            <div class="title">同比去年</div>
            <div class="number">{{ performance.yearOnYearByUp || 0 }}%</div>
          </div>
        </div>
      </div>
    </template>

    <template v-if="activeType === 3">
      <div class="bottom_wrap">
        <div class="bottom_title">本月</div>
        <div class="bottom_item">
          <div class="item_wrap">
            <div class="title">销售目标</div>
            <div class="number">{{ performance.monthSellTarget || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">实际销售</div>
            <div class="number">{{ performance.actualSales || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">达成率</div>
            <div class="number">{{ performance.achievementRate || 0 }}%</div>
          </div>
          <div class="item_wrap">
            <div class="title">本月同比</div>
            <div class="number">{{ performance.yearOnYear || 0 }}%</div>
          </div>
        </div>
      </div>
      <div class="bottom_wrap">
        <div class="bottom_title">本年</div>
        <div class="bottom_item">
          <div class="item_wrap">
            <div class="title">销售目标</div>
            <div class="number">{{ performance.yearSellTarget || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">实际销售</div>
            <div class="number">{{ performance.actualSalesByUp || 0 }}</div>
          </div>
          <div class="item_wrap">
            <div class="title">达成率</div>
            <div class="number">
              {{ performance.achievementRateByUp || 0 }}%
            </div>
          </div>
          <div class="item_wrap">
            <div class="title">同比去年</div>
            <div class="number">{{ performance.yearOnYearByUp || 0 }}%</div>
          </div>
        </div>
      </div>
    </template>
  </div>
</template>

<script>
import { performanceVersion } from '@/request/store/K_KPIAnalysis'
export default {
  data() {
    return {
      monthTypeList: [
        {
          type: 1,
          name: '本日'
        },
        {
          type: 2,
          name: '本周'
        },
        {
          type: 3,
          name: '本月'
        }
      ],
      activeType: 1,
      performance: {}
    }
  },
  created() {
    this.performanceVersion(this.activeType)
  },
  methods: {
    // 获取业绩看板数据
    async performanceVersion(type) {
      const { data } = await performanceVersion(type)
      if (data && data.code === 200) {
        this.performance = data.data
      }
      console.log(this.performance)
    },
    chooseMonthType(item) {
      this.activeType = item.type
      this.performanceVersion(this.activeType)
    }
  }
}
</script>

<style lang="less" scoped>
.results_wrap {
  .top_wrap {
    // height: 350px;
    padding-bottom: 20px;
    background-color: #f7f7f7;
    .t_top_wrap {
      display: flex;
      justify-content: space-between;
      .t_left {
        padding-top: 15px;
        margin-left: 30px;
        width: 150px;
        height: 80px;
        text-align: center;
        .t_left_titel {
          color: #7a7a7a;
        }
        .t_left_num {
          font-size: 20px;
          font-weight: 700;
          color: #017aff;
        }
      }
      .t_bottom {
        margin-top: 15px;
        width: 150px;
        height: 80px;
        padding-top: 20px;
        margin-right: 20px;
        .item_wrap {
          display: flex;
          justify-content: space-evenly;
          align-items: center;
          background-color: #fff;
          .t_bottom_item {
            padding: 5px 8px;
            color: #7a7a7a;
            cursor: pointer;
          }
          .active_item {
            padding: 4px 8px;
            color: #7a7a7a;
            cursor: pointer;
            border: 1px solid #1b7ffc;
          }
        }
        // margin-right: 20px;
        // margin-top: 30px;
        // height: 35px;
        // padding: 3px 10px;
        // background-color: rgb(252, 99, 99);
        // .t_bottom_item {
        //   color: #7a7a7a;
        //   border: 1px solid red;
        // }
      }
    }
    .t_bottom_wrap {
      margin-top: 20px;
      .t_tottom_top_wrap {
        display: flex;
        justify-content: space-around;
        .item_wrap {
          align-items: center;
          text-align: center;
          width: 120px;
          height: 80px;
          .title {
            padding-top: 15px;
            color: #7a7a7a;
          }
          .number {
            font-size: 20px;
            margin-top: 3px;
            font-weight: 700;
          }
        }
      }
      .t_tottom_bottom_wrap {
        display: flex;
        justify-content: space-around;
        margin-top: 20px;
        .item_wrap {
          align-items: center;
          text-align: center;
          width: 120px;
          height: 80px;
          .title {
            padding-top: 15px;
            color: #7a7a7a;
          }
          .number {
            font-size: 20px;
            margin-top: 3px;
            font-weight: 700;
          }
        }
      }
    }
  }
  .bottom_wrap {
    margin-top: 16px;
    padding-bottom: 16px;
    border: 1px solid #f7f7f7;
    .bottom_title {
      height: 40px;
      line-height: 40px;
      padding-left: 16px;
      background-color: #f7f7f7;
      font-weight: 600;
    }
    .bottom_item {
      display: flex;
      justify-content: space-evenly;
      margin-top: 20px;
      .item_wrap {
        width: 120px;
        height: 60px;
        text-align: center;
        .title {
          color: #7a7a7a;
          padding-top: 5px;
        }
        .number {
          margin-top: 5px;
          font-weight: 700;
          font-size: 20px;
        }
      }
    }
  }
}
</style>
